//
//  QianBaoChongViewController.m
//  DBAChain
//
//  Created by Evan on 2018/9/9.
//  Copyright © 2018 Evan. All rights reserved.
//

#import "QianBaoChongViewController.h"
#import "CommonData.h"
#import "taskOverviewService.h"
#import "SGQRCodeTool.h"
#import "dataCodeInfo.h"

@interface QianBaoChongViewController ()
@property (weak, nonatomic) IBOutlet UILabel *lbcode;
@property (weak, nonatomic) IBOutlet UIImageView *codeImage;
@property (weak, nonatomic) IBOutlet UILabel *lbcontent;
@property (weak, nonatomic) IBOutlet UIButton *imageButton;
@property (weak, nonatomic) IBOutlet UIButton *button;

@end

@implementation QianBaoChongViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"收款地址";
    [self initUI];
    self.topBgView.hidden = NO;
    
    self.lbcode.text = [UserCenter shareCenter].user.BurseQrCode;
    self.codeImage.image = [SGQRCodeTool SG_generateWithDefaultQRCodeData:[UserCenter shareCenter].user.BurseQrCode imageViewWidth:204];
}

-(void)initUI{
    self.button.backgroundColor = COLOR_main;
    self.button.layer.masksToBounds = YES;
    self.button.layer.borderWidth = 1.0f;
    self.button.layer.borderColor = [UIColor clearColor].CGColor;
    self.button.layer.cornerRadius = 20.0f;
    

    self.topBgView.layer.shadowColor = [UIColor blackColor].CGColor;
    //        阴影的透明度
    self.topBgView.layer.shadowOpacity = 0.2f;
    self.topBgView.layer.shadowOffset = CGSizeMake(0, 0 );
    //        阴影的圆角
    self.topBgView.layer.shadowRadius = 4.0f;
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self setBlackStatus:YES];

    if (self.navigationController.navigationBar.hidden == YES) {
        self.navigationController.navigationBar.hidden = NO;
    }
}

- (IBAction)copyAction:(id)sender {
    UIPasteboard *Pasteboard = [UIPasteboard generalPasteboard];
    [Pasteboard setString:self.lbcode.text];
    if (Pasteboard == nil) {
        [DKProgressHUD showErrorWithStatus:@"复制失败"];
    }else{
        [DKProgressHUD showSuccessWithStatus:@"复制成功"];
    }
}

- (IBAction)saveImageAction:(id)sender {
    [self loadImageFinished:self.codeImage.image];
}

- (void)loadImageFinished:(UIImage *)image
{
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (__bridge void *)self);
}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    if(error){
        [DKProgressHUD showErrorWithStatus:@"保存图片失败"];
    }else{
        [DKProgressHUD showErrorWithStatus:@"保存图片成功"];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
